<?php
require_once 'PHPUnit/Framework.php';

require_once dirname(__FILE__).'/../../../core/core.php';
CCore::Using('mime.attachments');
CCore::Using('mime.charsets');
CCore::Using('mime.mimeparts');

/**
 * Test class for CCoreMimeAttachments.
 */
class CCoreMimeAttachmentsTest extends PHPUnit_Framework_TestCase
{
	/**
	 * @var CCoreMimeCharsets
	 */
	protected $charsets;

	/**
	 * @var CCoreMimeAttachment
	 */
	protected $attachment;

	/**
	 * @var CCoreMimeAttachments
	 */
	protected $object;

	protected function setUp()
	{
		$sRawMime = file_get_contents(
			dirname(__FILE__).'/../../../core/examples/eml/simple with attachment.eml');
		
		$sRawMimeAttachment = file_get_contents(
			dirname(__FILE__).'/../../../core/examples/eml/mime attachment.eml');

		$this->charsets = new CCoreMimeCharsets();

		$oMimeMessage = new CCoreMimeMimePart($this->charsets, $sRawMime);
		$oMimeAttachment = new CCoreMimeMimePart($this->charsets, $sRawMimeAttachment);

		$this->attachment = new CCoreMimeAttachment($this->charsets, $oMimeAttachment);
		$this->object = new CCoreMimeAttachments($this->charsets, $oMimeMessage);
	}

	public function testAdd()
	{
		$this->assertEquals($this->object->Count(), 1);
		$this->object->Add($this->attachment);
		$this->assertEquals($this->object->Count(), 2);
		$this->object->Clear();
		$this->assertEquals($this->object->Count(), 0);
	}

	/**
	 * @todo Implement testFileName().
	 */
	public function testFileName()
	{
		$sFileName = $this->attachment->FileName();

		$this->assertType('string', $sFileName);
		$this->assertEquals($sFileName, 'av-7.gif');
	}

	public function testGetBinaryBody()
	{
		$sBinaryBody = $this->attachment->GetBinaryBody();

		$this->assertType('string', $sBinaryBody);
	}
}
